package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ArchiveCtg;
import com.ruoyi.system.service.IArchiveCtgService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 旧档案分类Controller
 * 
 * @author zzr
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/system/ctg")
public class ArchiveCtgController extends BaseController
{
    @Autowired
    private IArchiveCtgService archiveCtgService;

    /**
     * 查询旧档案分类列表
     */
    @GetMapping("/list")
    public AjaxResult list(ArchiveCtg archiveCtg)
    {
        List<ArchiveCtg> list = archiveCtgService.selectArchiveCtgList(archiveCtg);
        return success(list);
    }

    /**
     * 导出旧档案分类列表
     */
    @Log(title = "旧档案分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveCtg archiveCtg)
    {
        List<ArchiveCtg> list = archiveCtgService.selectArchiveCtgList(archiveCtg);
        ExcelUtil<ArchiveCtg> util = new ExcelUtil<ArchiveCtg>(ArchiveCtg.class);
        util.exportExcel(response, list, "旧档案分类数据");
    }

    /**
     * 获取旧档案分类详细信息
     */
    @GetMapping(value = "/{fondsNo}")
    public AjaxResult getInfo(@PathVariable("fondsNo") String fondsNo)
    {
        return success(archiveCtgService.selectArchiveCtgByFondsNo(fondsNo));
    }

    /**
     * 新增旧档案分类
     */
    @Log(title = "旧档案分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveCtg archiveCtg)
    {
        return toAjax(archiveCtgService.insertArchiveCtg(archiveCtg));
    }

    /**
     * 修改旧档案分类
     */
    @Log(title = "旧档案分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveCtg archiveCtg)
    {
        return toAjax(archiveCtgService.updateArchiveCtg(archiveCtg));
    }

    /**
     * 删除旧档案分类
     */
    @Log(title = "旧档案分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fondsNos}")
    public AjaxResult remove(@PathVariable String[] fondsNos)
    {
        return toAjax(archiveCtgService.deleteArchiveCtgByFondsNos(fondsNos));
    }
}
